#include "LinearColorMap.h"

LinearColorMap* newLinearColorMap() {
	LinearColorMap* map;
	map = (LinearColorMap*) malloc(sizeof(LinearColorMap));
	map->init();
	return map;
}

void LinearColorMap::init() {
	redMap = newLinearInterpolationMap();
	greenMap = newLinearInterpolationMap();
	blueMap = newLinearInterpolationMap();
}

ValuePoint* LinearColorMap::makePoint(int inputValue, int colorValue) {
	ValuePoint *point = newValuePoint();
	point->inputValue = inputValue;
	point->outputValue = colorValue;
	return point;
}

void LinearColorMap::addRedPoint(int inputValue, int colorValue) {
	ValuePoint *point = makePoint(inputValue, colorValue);
	redMap->addPoint(point);
}

void LinearColorMap::addGreenPoint(int inputValue, int colorValue) {
	ValuePoint *point = makePoint(inputValue, colorValue);
	greenMap->addPoint(point);
}

void LinearColorMap::addBluePoint(int inputValue, int colorValue) {
	ValuePoint *point = makePoint(inputValue, colorValue);
	blueMap->addPoint(point);
}

RGB LinearColorMap::getColorForValue(int inputValue) {
	int red = redMap->mapInputValue(inputValue);
	int green = greenMap->mapInputValue(inputValue);
	int blue = blueMap->mapInputValue(inputValue);

	RGB color;
	color.r = red;
	color.g = green;
	color.b = blue;
	return color;
}
